package com;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class TestCloneReference {
	public static void main(String[] args) throws CloneNotSupportedException {
	  /*  Employer employer = new Employer();
	    employer.setUsername("arthinking");
	  
	    Employee employee = new Employee();
	    employee.setUsername("dongdong");
	    employee.setEmployer(employer);
	    employee.setHardEnum(HardEnum.GREEN);
	    
	    //employee2由employee深复制得到
	    Employee employee2 = (Employee) employee.clone();
	    //这样两个employee各自保存了两个employer
	    employee2.getEmployer().setUsername("Jason");
	    employee2.setHardEnum(HardEnum.RED);
	    System.out.println(employee.getEmployer().getUsername());
	    System.out.println(employee2.getEmployer().getUsername());
	    System.out.println(employee.getHardEnum());
	    System.out.println(employee2.getHardEnum());
	    */
		List<Map<String, Object>> rosterList = new ArrayList<Map<String, Object>>();
		
		final List<Integer> test = new ArrayList<Integer>();
		test.add(1);
		test.add(2);
		
		Object zhang = "zjamg";
		
		for (Integer temp : test) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("type", temp);
			map.put("entityList", temp);
			rosterList.add(map);
		}
		
		for (Iterator<Map<String, Object>> iterator = rosterList.iterator(); iterator.hasNext();) {  
           Object entry = (Object) iterator.next();  
           System.out.println(entry);  
       } 
	}
}

class Employer implements Cloneable{
    private String username;

	public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    @Override
    public Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}

class Employee implements Cloneable{
    private String username;
    private Employer employer;
    private HardEnum hardEnum;

    public HardEnum getHardEnum() {
		return hardEnum;
	}

	public void setHardEnum(HardEnum hardEnum) {
		this.hardEnum = hardEnum;
	}
    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }
    public Employer getEmployer() {
        return employer;
    }
    public void setEmployer(Employer employer) {
        this.employer = employer;
    }

    @Override
    public Object clone() throws CloneNotSupportedException {
        //克隆Employee对象并手动的进一步克隆Employee对象中包含的Employer对象
        Employee employee = (Employee)super.clone();
        employee.setEmployer((Employer) employee.getEmployer().clone());
        return employee;
    }
    
}